<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>配置项xAxis</title>
  <script src="./echarts.js"></script>
  <style lang="css">
    #chart1, #chart2 {
      width: 100%;
      height: 500px;
      border: 1px solid red;
      float: left;
    }
  </style>
</head>
<body>
  <div id="chart1"></div>
  <div id="chart2"></div>

  <script>
    const myChart1 = echarts.init(document.getElementById('chart1'));

    myChart1.setOption({
      legend: { // 图例
        type: 'plain',
        show: true,
        data: ['昨日销量', '今日销量', '明日销量']
      },
      // tooltip必须写在与legend同级才行
      tooltip: {
        show: true
      },
      grid: {
        left: '5%'
      },
      xAxis: {
        show: true,
        gridIndex: 0,
        position: 'bottom',
        // offset: -100,
        type: 'category',
        data: ['衬衫', '羊毛衫', '雪纺衫', '裤子', '高跟鞋', { value: '袜子' }],
        // min: 0, // 在类目轴当中代表的是索引
        // max ({min, max}) {
        //   return 40
        // },
        // interval: 5,
        name: 'x轴',
        nameLocation: 'middle',
        nameGap: 20,
        inverse: false,
        boundaryGap: true,
        // splitNumber: 10,
        scale: false,
        // 坐标轴标签相关设置
        axisLabel: {
          show: true,
          rotate: 40,
          margin: 8,
          inside: false,
          interval: 0,
          formatter: '{value}',
          fontSize: 12,
          fontWeight: 'normal',
          fontStyle: 'normal',
          color: '#666',
          showMinLabel: true,
          showMaxLabel: true,
          backgroundColor: 'yellow',
          shadowColor: 'rgba(255, 0, 0, 0.2)',
          shadowOffsetX: 3,
          shadowOffsetY: 3,
        },
        // 坐标轴刻度相关设置
        axisTick: {
          show: true,
          interval: 2,
          inside: false,
          length: 4,
          alignWithLabel: false,
          lineStyle: {
            color: 'red',
            width: 1,
            type: 'solid'
          }
        },
        // 分割线
        splitLine: {
          show: true,
          interval: 0,
          lineStyle: {
            color: 'red',
            width: 1,
            type: 'solid'
          }
        },
        minorSplitLine: {
          show: false
        },
        axisPointer: {
          show: true
        }
      },
      yAxis: {
        left: 'left',
        axisPointer: {
          show: true
        }
      },
      series: [
        // {
        //   type: 'bar',
        //   data: [5, 10, 15, 20, 30, 40]
        //   // 当type为time时，连续的时序数据类似下面这样
        //   // data: [
        //   //   ['2025/01/01', 5],
        //   //   ['2025/01/02', 15],
        //   //   ['2025/01/03', 25],
        //   //   ['2025/01/04', 35],
        //   //   ['2025/01/05', 45],
        //   // ]
        // },
        {
          name: '昨日销量',
          type: 'bar',
          data: [5, 20, 36, 10, 10, 20]
        },
        {
          name: '今日销量',
          type: 'bar',
          data: [5, 20, 36, 10, 10, 20]
        },
        {
          name: '明日销量',
          type: 'bar',
          data: [5, 20, 36, 10, 10, 20]
        },
      ]
    })
  </script>
</body>
</html>